﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
using System.Threading;

namespace WeatherService
{
    public partial class WeatherService : ServiceBase
    {
        public WeatherService()
        {
            InitializeComponent();
        }

        Thread tCommon = new Thread(CommonHandler);
        /*线程终止标识*/
        public static bool bCommon = true;

        protected override void OnStart(string[] args)
        {
            bCommon = true;
            tCommon.IsBackground = true;
            tCommon.Start();
        }

        protected override void OnStop()
        {
            bCommon = false;

            #region Abort all threads
            try
            {
                if (tCommon != null)
                    tCommon.Abort();
            }
            catch (ThreadAbortException ex)
            {
                new WeatherBLL().WriteLog(ex.Message);
            }
            #endregion
        }

        /// <summary>
        /// webapi handler
        /// </summary>
        /// <param name="sender"></param>
        private static void CommonHandler(object sender)
        {
            new WeatherBLL().MainProcess(bCommon);
        }
    }
}
